import Vue from 'vue'
import VueRouter from 'vue-router'

const BooksPage = () => import('../views/BooksPage')
const BookDetail = () => import('../views/BookDetail')
const RecommendPage = () => import('../views/RecommendPage')
const ArticlePage = () => import('../views/ArticlePage')
const ArticleDetail = () => import('../views/ArticleDetail')
const CartPage = () => import('../views/CartPage')
const GiftPage = () => import('../views/GiftPage')
const Login = () => import('../views/Login')
const PersonalPage = () => import('../views/Personal')
const SearchPage = () => import('../views/Search')
const PreSalePage = () => import('../views/RecommendPage/Carousel/PreSalePage')
const Editor = () => import('../views/Editor')
Vue.use(VueRouter)

const routes = [
  // 图书页面
  { path: '/book', name: 'Book', component: BooksPage },
  // 图书详情
  {
    path: '/book/:bookId?',
    name: 'BookDetail',
    component: BookDetail
  },
  // 文章页面
  {
    path: '/article',
    name: 'Article',
    component: ArticlePage
  },
  // 文章详情页
  {
    name: 'ArticleDetail',
    path: '/article/:articleId?',
    component: ArticleDetail
  },
  // 购物袋页面
  {
    path: '/cart',
    name: 'Cart',
    component: CartPage
  },
  // 样书袋页面
  {
    path: '/gift',
    name: 'Gift',
    component: GiftPage
  },
  // 登录页面
  {
    name: 'Login',
    path: '/login',
    component: Login
  },
  // 个人中心页面
  {
    name: 'Space',
    path: '/space/:userId?',
    component: PersonalPage
  },
  // 搜索页面
  {
    path: '/search',
    name: 'Search',
    component: SearchPage
  },
  //预售
  {
    path: '/preSalePage',
    name: 'PreSalePage',
    component: PreSalePage
  },
  // 编辑页面
  {
    path: '/editor',
    name: 'Editor',
    component: Editor
  },
  // 推荐页面
  {
    path: '/',
    component: RecommendPage
  },
  {
    path: "*",
    redirect: "/",
  }
]

const router = new VueRouter({
  mode: 'history',
  routes,
  scrollBehavior() {
    return {
      x: 0,
      y: 0
    }
  }
})

export default router
